package com.iv.durian.cloud.service;

import com.iv.durian.cloud.User;
import com.iv.durian.cloud.dao.UserDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public User get(Integer id){
        return userDao.get(id,null,null,null);
    }
    public User get(String mobileOrEmail){
        if (StringUtils.contains(mobileOrEmail,"@")){
            return userDao.get(null,null,mobileOrEmail,null);
        }else {
            return  userDao.get(null,mobileOrEmail,null,null);
        }
    }

    public User getByTicket(String ticket){
        return  userDao.get(null,null,null,ticket);
    }

    public int add( User user){
        return userDao.add(user);
    }

    public int updatePassword(int id,String password){
        return userDao.updatePassword(id,password);
    }

    public int updateStatus(int id, int status){
        return userDao.updateStatus(id,status);
    }

    public List<User> list(Integer status, int offset, int limit){
        return userDao.list(status,offset,limit);
    }

    public int count(Integer status){
        return userDao.count(status);
    }

    public int updateTicket( int id, String ticket,long expire){
        return userDao.updateTicket(id,ticket,expire);
    }

    public int cleanTicket( int id){
        return userDao.cleanTicket(id);
    }
}
